package com.ywgt.system.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.ywgt.system.pojo.Product;
import com.ywgt.system.mapper.ProductMapper;
import com.ywgt.system.service.ProductService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yiping
 * @since 2021-01-22
 */
@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements ProductService {
    @Autowired
    private ProductMapper productMapper;
    @Override
    public Page<Product> findAllStocks(Integer pageNum, Integer pageSize, String name, String categorys) {
        String [] ids=null;
        String oneCategoryId=null;
        String twoCategoryId=null;
        String threeCategoryId=null;
        if (!StringUtils.isEmpty(categorys)) {
            ids = categorys.split(",");
            switch (ids.length){
                case 1: oneCategoryId=ids[0];
                break;
                case 2: oneCategoryId=ids[0];
                        twoCategoryId=ids[1];
                    break;
                case 3: oneCategoryId=ids[0];
                        twoCategoryId=ids[1];
                        threeCategoryId=ids[2];
                    break;
            }
        }
        PageHelper.startPage(pageNum,pageSize);
        return productMapper.findAllStocks(name,oneCategoryId,twoCategoryId,threeCategoryId);
    }
}
